package com.benshou.bcss.common.db.query;

import com.baomidou.mybatisplus.core.conditions.AbstractLambdaWrapper;
import com.baomidou.mybatisplus.core.conditions.ISqlSegment;
import com.baomidou.mybatisplus.core.conditions.interfaces.Compare;
import com.baomidou.mybatisplus.core.conditions.interfaces.Func;
import com.baomidou.mybatisplus.core.conditions.interfaces.Join;
import com.baomidou.mybatisplus.core.conditions.interfaces.Nested;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import lombok.NonNull;

/**
 * 基于 Lambda 的查询参数设置接口
 * <p>
 *     同时适配
 *     {@code com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper}
 *     {@code com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper} 。
 * </p>
 *
 * @author <a href="mailto:liuzhenbang@benshou.com">Liu Zhenbang</a>
 */
@FunctionalInterface
public interface LambdaQueryApplicator<T> {

    /**
     * 应用查询参数
     *
     * @param query 承载查询参数的对象
     * @return 传入值本身
     * @param <Q> 承载查询参数的对象的类型
     */
    <
            Q extends
                    Compare<Q, SFunction<T, ?>> &
                    Func<Q, SFunction<T, ?>> &
                    Join<Q> &
                    Nested<L, Q> &
                    ISqlSegment,
            L extends AbstractLambdaWrapper<T, L>>
    Q applyQuery(@NonNull Q query);
}
